package com.feeyo.groundservice.composewidget.usage

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import com.feeyo.groundservice.base_util.toast
import com.feeyo.groundservice.composewidget.usage.base.BaseComposeActivity
import com.feeyo.groundservice.composewidget.view.value_selector.ValueSelector
import com.feeyo.groundservice.composewidget.view.value_selector.date_selector.DateSelector
import com.feeyo.groundservice.composewidget.view.value_selector.date_selector.DateSelectorState
import com.feeyo.groundservice.composewidget.view.value_selector.rememberValueSelectState
import java.util.Calendar

/**
 *作者：QLH on 2023-08-13
 *描述：
 */
class DateSelectorActivity : BaseComposeActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            Column(
                modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState())
            ) {
                ValueSample()
                DateSample()
                DateSample1()
            }
        }
    }


    @Composable
    private fun ValueSample() {
        val values = remember { ArrayList((0 until 60).map(Int::toString)) }
        val state = rememberValueSelectState()
        ValueSelector(
            values = values,
            state = state,
            defaultSelectIndex = 10
        )
        Button({
            toast(values[state.getSelectIndex()])
        }) {
            Text("获取当前值")
        }
    }

    @Composable
    private fun DateSample() {
        val currentDate = Calendar.getInstance()
        val year = currentDate.get(Calendar.YEAR)
        val month = currentDate.get(Calendar.MONTH)
        val day = currentDate.get(Calendar.DAY_OF_MONTH)

        val state = remember { DateSelectorState(year, month + 1, day) }
        DateSelector(state)
        Button({
            toast("${state.getYear()}.${state.getMonth()}.${state.getDay()}")
        }) {
            Text("获取当前值")
        }
    }

    @Composable
    private fun DateSample1() {
        val currentDate = Calendar.getInstance()
        val year = currentDate.get(Calendar.YEAR)
        val month = currentDate.get(Calendar.MONTH)
        val day = currentDate.get(Calendar.DAY_OF_MONTH)

        val state = remember {
            DateSelectorState(year, month + 1, day, isShowDay = false) }
        DateSelector(state)
        Button({
            toast("${state.getYear()}.${state.getMonth()}.${state.getDay()}")
        }) {
            Text("获取当前值")
        }
    }
}